/*
 *    This file is part of BlobDB.
 *
 *    BlobDB is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    BlobDB is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with BlobDB.  If not, see <http://www.gnu.org/licenses/>.
 *    
 *    Copyright(c) 2011 Michael Kankkonen
 *    http://www.vnetcon.org
 */


package org.vnetcon.blobdb.database.ws;


import java.util.List;

import org.vnetcon.blobdb.database.BatchStatements;
import org.vnetcon.blobdb.database.ResultSet;
import org.vnetcon.blobdb.database.Statement;

public class WsStatement {
	
	public WsStatement(){
	}

	
	public String executeUpdate(String sql, String username, String password){
		String strRet = "";
		Statement stmt = null;

		try {
			stmt = new Statement();
			try {
				strRet = stmt.executeUpdateFromWebService(sql, username, password);
			} catch (Exception ex) {
				strRet = "error:" + ex.getMessage();
			}
			return strRet;
		} catch (Exception ex) {
			strRet = "error: " + ex.getMessage();
		}
		
		stmt = null;
		Runtime.getRuntime().gc();
		return strRet;
	}

	public String executeBatchUpdate(BatchStatements batch, String username, String password){
		String strRet = "";
		Statement stmt = null;
		try {
			stmt = new Statement();
			try {
				strRet = stmt.executeBatchUpdateFromWebService(batch.getbSQLStatements(), username, password);
			} catch (Exception ex) {
				strRet = "error:" + ex.getMessage();
			}
			return strRet;
		} catch (Exception ex) {
			strRet = "error: " + ex.getMessage();
		}
		stmt = null;
		Runtime.getRuntime().gc();
		return strRet;
	}
	
	
	public ResultSet executeQuery(String sql, String username, String password){
		ResultSet rs = new ResultSet();
		Statement stmt = null;
		try {
			stmt = new Statement();
			try {
				rs = stmt.executeQueryFromWebService(sql, username, password);
				rs.setStatusMessage("ok:");
			} catch (Exception ex) {
				rs.setStatusMessage("error:" + ex.getMessage());
			}
		} catch (Exception ex) {
			rs.setStatusMessage("error: " + ex.getMessage());
		}
		stmt = null;
		Runtime.getRuntime().gc();
		return rs;
	}

	public ResultSet executeRangeQuery(String sql, String username, String password, int rangeStart, int rangeEnd){
		ResultSet rs = new ResultSet();
		Statement stmt = null;
		try {
			stmt = new Statement();
			try {
				rs = stmt.executeQueryFromWebService(sql, username, password, rangeStart, rangeEnd);
				rs.setStatusMessage("ok:");
			} catch (Exception ex) {
				rs.setStatusMessage("error:" + ex.getMessage());
			}
		} catch (Exception ex) {
			rs.setStatusMessage("error: " + ex.getMessage());
		}
		stmt = null;
		return rs;
	}
	
}
